<template>
	<view class="jifenshangcheng">
		<js-navbar title="积分商城" fontColor="#000000" :navStyle="{ position: 'fixed' }" :opacity="opacity" center backIcon></js-navbar>
		<view class="hboxbox">
			<view class="hbox">
				<view class="row">
					<view class="lbox">
						<text>{{ user_info.jifen }}</text>
						<text>积分</text>
					</view>
					<view class="rbox">
						<button @click="toNav(`jifenshangcheng/dhjilu`)">兑换记录</button>
					</view>
				</view>
				<text>积分明细</text>
			</view>
		</view>

		<view class="container">
			<!-- <u-sticky :offsetTop="0"> -->
			<view class="filtrate">
				<view class="item" :class="{ active: nowVal.name === item.name }" @click="handleItem(item)" v-for="(item, i) in tabs" :key="i">
					<text>{{ item.name }}</text>
					<view class="glimg" v-if="item.filter">
						<image v-if="nowVal.id === item.id && item.val === 2" src="@/static/images/ssja.png" mode="aspectFit"></image>
						<image v-else src="@/static/images/ssj.png" mode="aspectFit"></image>
						<image v-if="nowVal.id === item.id && item.val === 3" src="@/static/images/xsja.png" mode="aspectFit"></image>
						<image v-else src="@/static/images/xsj.png" mode="aspectFit"></image>
					</view>
				</view>
			</view>
			<!-- </u-sticky> -->

			<!-- <scroll-view scroll-y="true" class="scroll-y003"> -->
			<view class="cbox">
				<card-list :list="list" @getItem="getItem"></card-list>
				<u-loadmore :status="status" />
			</view>
			<!-- </scroll-view> -->
		</view>
	</view>
</template>

<script>
import API from '@/common/api';
import { get_userInfo } from '@/common/common_fun';
export default {
	name: 'jifenshangcheng',
	data() {
		return {
			opacity: 1,
			status: '',
			tabs: [
				{
					id: 1,
					name: '综合',
					val: 0,
				},
				{
					id: 2,
					name: '销量',
					// filter: true,
					val: 1,
				},
				{
					id: 3,
					name: '价格',
					filter: true,
					val: 2,
				}
			],

			nowVal: {
					id: 1,
					name: '综合',
					val: 0,
				},
			list: [],
			paging: {
				page: 1,
				pagenum: 10
			},
			user_info: {}
		};
	},
	onPageScroll(res) {
		res.scrollTop > 10 ? (this.opacity = 0) : (this.opacity = 1);
	},
	onLoad() {
		this.reset();
		this.init();
	},
	onShow() {
		get_userInfo((data) => {
			this.user_info = data;
		});
	},
	onReachBottom() {
		if (this.status === 'nomore') return;
		this.init(this.current);
	},
	methods: {
		init() {
			API.getJson('money_jifenPdts', { order: this.nowVal.val, ...this.paging }).then((res) => {
				const { code, data, message } = res;
				if (code === 1) {
					if (data.length !== 0) this.list = this.list.concat(data);
					if (this.paging.pagenum === data.length) {
						this.paging.page += 1;
						this.status = 'loadmore';
					} else {
						this.status = 'nomore';
					}
				}
			});
		},
		handleItem(item) {
			this.reset();
			if (item.filter) {
				if (item.id === this.nowVal.id) item.val = this.nowVal.val === 2 ? 3 : 2 || 2;
			} else {
				this.tabs.forEach((item) => item.filter && (item.val = 2));
			}
			this.nowVal = item;
				console.log(item);
			this.init();
		},
		getItem(item) {
			console.log(item);
			// return
			this.toNav(`jifenshangcheng/shangpin_details?id=${item.inventoryId}`);
		},
		reset() {
			this.paging.page = 1;
			this.list = [];
		},
		handleActive(e) {
			this.tabval = e.name;
			console.log(e);
		}
	}
};
</script>

<style lang="less" scoped>
.jifenshangcheng {
	position: relative;
	z-index: 1;
	.scroll-y003 {
		height: calc(100vh - 336rpx - 88rpx - 48rpx);
	}
	.container {
		padding: 24rpx 32rpx;
	}
	.hboxbox {
		position: relative;
		width: 750rpx;
		height: 336rpx;

		background: linear-gradient(135deg, #ffe9cc 0%, #f2cea1 100%);
			overflow: hidden;
		.hbox {
			// position: absolute;
			position: sticky;
			top: 0;
			margin-top: calc(336rpx / 2);
			// bottom: 0;
			padding: 28rpx 32rpx;
			overflow: hidden;
			width: 750rpx;
			& > text {
				margin-top: 14rpx;
				font-size: 24rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #53361e;
			}
			.row {
				.flex-between();
				.lbox {
					text:nth-of-type(1) {
						margin-right: 16rpx;
						font-size: 48rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #53361e;
					}
					text:nth-of-type(2) {
						font-size: 24rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #53361e;
					}
				}
				.rbox {
					button {
						.flex-center();
						background: transparent;
						width: 144rpx;
						height: 40rpx;
						border-radius: 20rpx 20rpx 20rpx 20rpx;
						border: 2rpx solid #000000;
						font-size: 24rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #000000;
					}
				}
			}
		}
	}

	.cbox {
		padding: 16rpx 0;
	}

	.tabs-box {
		height: 88rpx;
		background: #ffffff;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		display: flex;

		.item {
			position: relative;
			flex: 1;
			transition: 0.3s all;
			.flex-center();
			text {
				font-size: 28rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #000000;
			}
			image {
				margin-left: 5rpx;
				margin-top: 5rpx;
				width: 20rpx;
				height: 20rpx;
			}
		}
		.active {
			.bline {
				position: absolute;
				bottom: 0;
				width: 3em;
				height: 4rpx;
				background: @basecolor;
				border-radius: 2rpx;
			}
		}
	}
}
</style>
